package com.cloudbroker.bcs.platform.dav.middle.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cloudbroker.bcs.common.model.Pagination;
import com.cloudbroker.bcs.platform.dav.bizapi.service.business.plugs.result.PlugsDavListData;
import com.cloudbroker.bcs.platform.dav.middle.dao.PlugsDAO;
import com.cloudbroker.bcs.platform.dav.middle.entity.Plugs;
import com.cloudbroker.bcs.platform.dav.middle.service.PlugsService;
import com.cloudbroker.bcs.platform.dav.middle.service.base.TenantServiceImplBase;

@Service
public class PlugsServiceImpl extends TenantServiceImplBase<Plugs, String> implements PlugsService{

	@Resource
	private PlugsDAO plugsDAO;

	@Override
	protected PlugsDAO getDAO(){
		return plugsDAO;
	}

	@Override
	public List<PlugsDavListData> queryPlugsForWeb(Plugs plugs,Pagination page) {
        int count = count(plugs);
        if (null == page) {
            page = plugs.getPage();
        }
        page.setTotal_item_num(count);
        int startIndex = (page.getPage_no() <= 0 ? 0 : page.getPage_no() - 1) * page.getPage_size();
        page.setStart_index(startIndex);
        plugs.setPage(page);
		return plugsDAO.queryPlugsForWeb(plugs);
	}

	@Override
	public List<Plugs> checkExist(String name, String code,String link) {
		return plugsDAO.checkExist(name, code,link);
	}

	@Override
	public Long getMaxSort(Plugs form) {
		Long maxNum = plugsDAO.getMaxSort(form);
		return maxNum == null ? 0 : maxNum+1L;
	}

    @Override
    public void deleteAll() {
        plugsDAO.deleteAll();
    }

	@Override
	public void updateBuyCount(Plugs plugs) {
		plugsDAO.updateBuyCount(plugs);
	}
}
